<%@ page import="com.hurst.Contractor" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="layout" content="main" />
        <g:set var="entityName" value="${message(code: 'contractor.label', default: 'Contractor')}" />
        <title><g:message code="default.create.label" args="[entityName]" /></title>
    </head>
    <body>

        <div class='addWorkLink'><g:link action='create' controller="workWeek" params="[contractorId: contractor.id]">Add Work Week</g:link></div>
        <div class="body" id='content'>
            <div class="list">
                <table>
                    <thead>
                        <tr>
                            <th><g:message code="workweek" default="Week Starting on" /></th>

                            <th><g:message code="managerAgreed" default="Confirmed By Manager" /></th>
                            <th><g:message code="view" default="View" /></th>
                            <th><g:message code="pdf" default="Create Pdf" /></th>
                            <th><g:message code="delete" default="Delete" /></th>
                            <th><g:message code="email" default="Email" /></th>

                        </tr>
                    </thead>
                    <tbody>
                    <g:each in="${contractor.workWeeks.sort{a, b->b.startDate <=> a.startDate}}" status="i" var="workWeekInstance">
                        <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">

                            <td>${fieldValue(bean: workWeekInstance, field: "startDate")}</td>

                            <td>${fieldValue(bean: workWeekInstance, field: "managerAgreed")}</td>
                            <td><g:link action='view' controller="workWeek" params="[contractorId: contractor.id, id: workWeekInstance.id]">View</g:link></td>
                            <td><g:link action='pdf' controller="workWeek" params="[contractorId: contractor.id, id: workWeekInstance.id]">Create Pdf</g:link></td>
                            <td><g:link action='delete' controller="workWeek" params="[contractorId: contractor.id, id: workWeekInstance.id]">Delete</g:link></td>
                            <td><g:link action='sendInvoiceEmail' controller="workWeek" params="[contractorId: contractor.id, id: workWeekInstance.id]">Email</g:link></td>

                        </tr>
                    </g:each>
                    </tbody>
                </table>
            </div>
            <div class="paginateButtons">
                <g:paginate total="${contractor.workWeeks}" />
            </div>
        </div>
    </body>
</html>